﻿using DiaoPaiDaYin;
using DXApplicationTangche.UC.款式异常;
using DXApplicationTangche.UC.门店下单.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.service
{
    /// <summary>
    /// 款式服务
    /// </summary>
    public class StyleService
    {

        public static 款式图片一览Dto getStyleByORDER_ID(String ORDER_ID)
        {
            String sql = "SELECT\n" +
                "	SYS_STYLE_ID,\n" +
                "	CUSTOMER_COUNT_ID,\n" +
                "	STYLE_CD,\n" +
                "	STYLE_CATEGORY_CD,\n" +
                "	STYLE_DRESS_CATEGORY,\n" +
                "	STYLE_DESIGN_TYPE,\n" +
                "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                "	REF_STYLE_ID,\n" +
                "	STYLE_NAME_CN,\n" +
                "	STYLE_NAME_EN,\n" +
                "	STYLE_FIT_CD,\n" +
                "	SYTLE_YEAR,\n" +
                "	SYTLE_SEASON,\n" +
                "	SYTLE_FABRIC_ID,\n" +
                "	STYLE_SIZE_GROUP_CD,\n" +
                "	STYLE_SIZE_CD,\n" +
                "	STYLE_MAKE_TYPE,\n" +
                "	STYLE_MATERIAL_NUMBER,\n" +
                "	STYLE_DESIGN_PRICE,\n" +
                "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                "	SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME,\n" +
                "	ENABLE_FLAG,\n" +
                "	CREATE_DATE\n" +
                "FROM\n" +
                "	s_style_p\n" +
                " where s_style_p.SYS_STYLE_ID in (select STYLE_ID from o_order_p where order_id = '" + ORDER_ID+"')" +
                "	order by CREATE_DATE";

            List<款式图片一览Dto> 款式图片一览Dtos = new List<款式图片一览Dto>();

            DataTable dataTable = SQLmtm.GetDataTable(sql);
            foreach (DataRow dataRow in dataTable.Rows)
            {
                return new 款式图片一览Dto(dataRow);
            }           
            throw new Exception("没有款式信息");

        }

        /// <summary>
        /// 取得所有款式信息
        /// </summary>
        /// <returns></returns>
        public static 款式Model getAllStyle(byte ENABLE_FLAG)
        {
            String sql = "SELECT\n" +
                "	SYS_STYLE_ID,\n" +
                "	CUSTOMER_COUNT_ID,\n" +
                "	STYLE_CD,\n" +
                "	STYLE_CATEGORY_CD,\n" +
                "	STYLE_DRESS_CATEGORY,\n" +
                "	STYLE_DESIGN_TYPE,\n" +
                "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                "	REF_STYLE_ID,\n" +
                "	STYLE_NAME_CN,\n" +
                "	STYLE_NAME_EN,\n" +
                "	STYLE_FIT_CD,\n" +
                "	SYTLE_YEAR,\n" +
                "	SYTLE_SEASON,\n" +
                "	SYTLE_FABRIC_ID,\n" +
                "	STYLE_SIZE_GROUP_CD,\n" +
                "	STYLE_SIZE_CD,\n" +
                "	STYLE_MAKE_TYPE,\n" +
                "	STYLE_MATERIAL_NUMBER,\n" +
                "	STYLE_DESIGN_PRICE,\n" +
                "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                "	SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME,\n" +
                "	ENABLE_FLAG,\n" +
                "	CREATE_DATE\n" +
                "FROM\n" +
                "	v_style_p\n" +
                " where v_style_p.ENABLE_FLAG = '" + ENABLE_FLAG + "'" +
                "	order by CREATE_DATE";
            List<款式图片一览Dto> 款式图片一览Dtos = new List<款式图片一览Dto>();

            List<String> FIT_CDs = new List<string>();  //  版型id
            DataTable dataTable = SQLmtm.GetDataTable(sql);
            foreach (DataRow dataRow in dataTable.Rows)
            {
                款式图片一览Dto 款式图片一览Dto = new 款式图片一览Dto(dataRow);
                款式图片一览Dtos.Add(款式图片一览Dto);
                if (!FIT_CDs.Contains(款式图片一览Dto.STYLE_FIT_CD))
                {
                    FIT_CDs.Add(款式图片一览Dto.STYLE_FIT_CD);    //  版型
                }
            }
            款式Model model = new 款式Model(款式图片一览Dtos);

            if (FIT_CDs.Count > 0)
            {
                sql = "SELECT DISTINCT\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD \n" +
                    "FROM\n" +
                    "	a_size_fit_p \n" +
                    "WHERE\n" +
                    "	FIT_CD IN ( '" + String.Join("','", FIT_CDs) + "' ) \n" +
                    "ORDER BY\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD";
                dataTable = SQLmtm.GetDataTable(sql);
                //List<String> EGS_GROUP_SIZEs = new List<string>();   //  数字尺码
                //List<String> IGS_GROUP_SIZEs = new List<string>();  //  英文尺码
                model.buildSizeFit(dataTable);
            }

            return model.buildView();
        }
        /// <summary>
        /// 通过款式id查询款式
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static 款式Model getStyleByID(String styleid)
        {
            String sql = "SELECT\n" +
                "	SYS_STYLE_ID,\n" +
                "	CUSTOMER_COUNT_ID,\n" +
                "	STYLE_CD,\n" +
                "	STYLE_CATEGORY_CD,\n" +
                "	STYLE_DRESS_CATEGORY,\n" +
                "	STYLE_DESIGN_TYPE,\n" +
                "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                "	REF_STYLE_ID,\n" +
                "	STYLE_NAME_CN,\n" +
                "	STYLE_NAME_EN,\n" +
                "	STYLE_FIT_CD,\n" +
                "	SYTLE_YEAR,\n" +
                "	SYTLE_SEASON,\n" +
                "	SYTLE_FABRIC_ID,\n" +
                "	STYLE_SIZE_GROUP_CD,\n" +
                "	STYLE_SIZE_CD,\n" +
                "	STYLE_MAKE_TYPE,\n" +
                "	STYLE_MATERIAL_NUMBER,\n" +
                "	STYLE_DESIGN_PRICE,\n" +
                "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                "	SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME,\n" +
                "	ENABLE_FLAG,\n" +
                "	CREATE_DATE\n" +
                "FROM\n" +
                "	s_style_p\n" +
                //" where s_style_p.ENABLE_FLAG = '1'" +
                " where s_style_p.SYS_STYLE_ID = '" + styleid+"'" +
                "	order by CREATE_DATE";
            List<款式图片一览Dto> 款式图片一览Dtos = new List<款式图片一览Dto>();

            List<String> FIT_CDs = new List<string>();  //  版型id
            DataTable dataTable = SQLmtm.GetDataTable(sql);
            foreach (DataRow dataRow in dataTable.Rows)
            {
                款式图片一览Dto 款式图片一览Dto = new 款式图片一览Dto(dataRow);
                款式图片一览Dtos.Add(款式图片一览Dto);
                if (!FIT_CDs.Contains(款式图片一览Dto.STYLE_FIT_CD))
                {
                    FIT_CDs.Add(款式图片一览Dto.STYLE_FIT_CD);    //  版型
                }
            }
            款式Model model = new 款式Model(款式图片一览Dtos);

            if (FIT_CDs.Count > 0)
            {
                sql = "SELECT DISTINCT\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD \n" +
                    "FROM\n" +
                    "	a_size_fit_p \n" +
                    "WHERE\n" +
                    "	FIT_CD IN ( '" + String.Join("','", FIT_CDs) + "' ) \n" +
                    "ORDER BY\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD";
                dataTable = SQLmtm.GetDataTable(sql);
                //List<String> EGS_GROUP_SIZEs = new List<string>();   //  数字尺码
                //List<String> IGS_GROUP_SIZEs = new List<string>();  //  英文尺码
                model.buildSizeFit(dataTable);
            }

            return model.buildView();
        }
        /// <summary>
        /// 取款式通过名字
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static 款式Model getStyleByNa(String name)
        {
            String sql = "SELECT\n" +
                    "	SYS_STYLE_ID,\n" +
                    "	CUSTOMER_COUNT_ID,\n" +
                    "	STYLE_CD,\n" +
                    "	STYLE_CATEGORY_CD,\n" +
                    "	STYLE_DRESS_CATEGORY,\n" +
                    "	STYLE_DESIGN_TYPE,\n" +
                    "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                    "	REF_STYLE_ID,\n" +
                    "	STYLE_NAME_CN,\n" +
                    "	STYLE_NAME_EN,\n" +
                    "	STYLE_FIT_CD,\n" +
                    "	SYTLE_YEAR,\n" +
                    "	SYTLE_SEASON,\n" +
                    "	SYTLE_FABRIC_ID,\n" +
                    "	STYLE_SIZE_GROUP_CD,\n" +
                    "	STYLE_SIZE_CD,\n" +
                    "	STYLE_MAKE_TYPE,\n" +
                    "	STYLE_MATERIAL_NUMBER,\n" +
                    "	STYLE_DESIGN_PRICE,\n" +
                    "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                    "	SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME,\n" +
                    "	ENABLE_FLAG,\n" +
                    "	CREATE_DATE \n" +
                    "FROM\n" +
                    "	s_style_p \n" +
                    "WHERE\n" +
                    "	s_style_p.STYLE_NAME_CN LIKE '%"+name+"%' \n" +
                    "	AND s_style_p.STYLE_KBN = 'STYLE_SOURCE-STYLE_SOURCE_40' \n"+
                    "ORDER BY\n" +
                    "	CREATE_DATE;";
            List<款式图片一览Dto> 款式图片一览Dtos = new List<款式图片一览Dto>();

            List<String> FIT_CDs = new List<string>();  //  版型id
            DataTable dataTable = SQLmtm.GetDataTable(sql);
            foreach (DataRow dataRow in dataTable.Rows)
            {
                款式图片一览Dto 款式图片一览Dto = new 款式图片一览Dto(dataRow);
                款式图片一览Dtos.Add(款式图片一览Dto);
                if (!FIT_CDs.Contains(款式图片一览Dto.STYLE_FIT_CD))
                {
                    FIT_CDs.Add(款式图片一览Dto.STYLE_FIT_CD);    //  版型
                }
            }
            款式Model model = new 款式Model(款式图片一览Dtos);

            if (FIT_CDs.Count > 0)
            {
                sql = "SELECT DISTINCT\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD \n" +
                    "FROM\n" +
                    "	a_size_fit_p \n" +
                    "WHERE\n" +
                    "	FIT_CD IN ( '" + String.Join("','", FIT_CDs) + "' ) \n" +
                    "ORDER BY\n" +
                    "	FIT_CD,\n" +
                    "	SIZEGROUP_CD,\n" +
                    "	SIZE_CD";
                dataTable = SQLmtm.GetDataTable(sql);
                //List<String> EGS_GROUP_SIZEs = new List<string>();   //  数字尺码
                //List<String> IGS_GROUP_SIZEs = new List<string>();  //  英文尺码
                model.buildSizeFit(dataTable);
            }

            return model.buildView();
        }
        /// <summary>
        /// 取得所有款式信息
        /// </summary>
        /// <returns></returns>
        public static List<款式图片一览Dto> getStyleByIds(List<String> ids)
        {
            String sql = "SELECT\n" +
                "	SYS_STYLE_ID,\n" +
                "	CUSTOMER_COUNT_ID,\n" +
                "	STYLE_CD,\n" +
                "	STYLE_CATEGORY_CD,\n" +
                "	STYLE_DRESS_CATEGORY,\n" +
                "	STYLE_DESIGN_TYPE,\n" +
                "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                "	REF_STYLE_ID,\n" +
                "	STYLE_NAME_CN,\n" +
                "	STYLE_NAME_EN,\n" +
                "	STYLE_FIT_CD,\n" +
                "	SYTLE_YEAR,\n" +
                "	SYTLE_SEASON,\n" +
                "	SYTLE_FABRIC_ID,\n" +
                "	STYLE_SIZE_GROUP_CD,\n" +
                "	STYLE_SIZE_CD,\n" +
                "	STYLE_MAKE_TYPE,\n" +
                "	STYLE_MATERIAL_NUMBER,\n" +
                "	STYLE_DESIGN_PRICE,\n" +
                "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                "	SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME,\n" +
                "	ENABLE_FLAG,\n" +
                "	CREATE_DATE\n" +
                "FROM\n" +
                "	v_style_p\n" +
                " where v_style_p.SYS_STYLE_ID in ('"+String.Join("','",ids)+"')" +
                "	order by CREATE_DATE";
            List<款式图片一览Dto> 款式图片一览Dtos = new List<款式图片一览Dto>();

            DataTable dataTable = SQLmtm.GetDataTable(sql);
            foreach (DataRow dataRow in dataTable.Rows)
            {
                款式图片一览Dto 款式图片一览Dto = new 款式图片一览Dto(dataRow);
                款式图片一览Dtos.Add(款式图片一览Dto);
            }
            return 款式图片一览Dtos;
        }
        /// <summary>
        /// 取得单个款式信息
        /// </summary>
        /// <param name="styleid"></param>
        /// <returns></returns>
        public static 款式图片一览Dto getStyleById(String styleid)
        {
            String sql= "SELECT\n" +
                    "	SYS_STYLE_ID,\n" +
                    "	SHOP_ID,\n" +
                    "	STYLE_NO,\n" +
                    "	CUSTOMER_COUNT_ID,\n" +
                    "	STYLE_CD,\n" +
                    "	STYLE_KBN,\n" +
                    "	STYLE_SOURCE,\n" +
                    "	STYLE_CATEGORY_CD,\n" +
                    "	STYLE_DRESS_CATEGORY,\n" +
                    "	STYLE_DESIGN_TYPE,\n" +
                    "	STYLE_PUBLISH_CATEGORY_CD,\n" +
                    "	REF_STYLE_ID,\n" +
                    "	STYLE_NAME_CN,\n" +
                    "	STYLE_NAME_EN,\n" +
                    "	STYLE_FIT_CD,\n" +
                    "	SYTLE_YEAR,\n" +
                    "	SYTLE_SEASON,\n" +
                    "	SYTLE_FABRIC_ID,\n" +
                    "	SYTLE_FABRIC_NO,\n" +
                    "	STYLE_COMPOSITION,\n" +
                    "	STYLE_DESCRIBE,\n" +
                    "	STYLE_COLOR_CD,\n" +
                    "	STYLE_COLOR_NAME,\n" +
                    "	STYLE_SIZE_GROUP_CD,\n" +
                    "	STYLE_SIZE_CD,\n" +
                    "	STYLE_MAKE_TYPE,\n" +
                    "	STYLE_FIT_BODY_TYPE,\n" +
                    "	STYLE_SEX_CD,\n" +
                    "	STYLE_STANDARD,\n" +
                    "	STYLE_BAR_CODE,\n" +
                    "	STYLE_DESIGNER_DATE,\n" +
                    "	STYLE_DESIGNER,\n" +
                    "	STYLE_MATERIAL_NUMBER,\n" +
                    "	STYLE_DESIGN_PRICE,\n" +
                    "	STYLE_FACTORY_TOTAL_PRICE,\n" +
                    "	STYLE_SHOP_TOTAL_PRICE,\n" +
                    "	REMARKS,\n" +
                    "	ENABLE_FLAG,\n" +
                    "	DELETE_FLAG,\n" +
                    "	VERSION,\n" +
                    "	CREATE_DATE,\n" +
                    "	UPDATE_DATE,\n" +
                    "	CREATE_USER,\n" +
                    "	UPDATE_USER,\n" +
                    "	COVER_PHOTO_PATH,\n" +
                    "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) ) AS PIC_URL,\n" +
                    "  SUBSTRING_INDEX( COVER_PHOTO_PATH, '/',- 1 ) AS PIC_NAME\n" +
                    "FROM\n" +
                    "	s_style_p \n" +
                    "WHERE SYS_STYLE_ID='"+styleid+"'";
            DataRow dr = SQLmtm.GetDataRow(sql);
            return new 款式图片一览Dto(dr);
        }
        /// <summary>
        /// 根据标准款取款式信息
        /// </summary>
        /// <param name="REF_STYLE_ID"></param>
        /// <returns></returns>
        public static DataRow generateStyleInfo(String REF_STYLE_ID)
        {
            String sql = "SELECT\n" +
                "	SYS_STYLE_ID,\n" +
                "	STYLE_SIZE_CD,\n" +
                "	STYLE_NAME_CN,\n" +
                "	SYTLE_YEAR,STYLE_DRESS_CATEGORY,STYLE_DESIGN_TYPE,\n" +
                "	SYTLE_SEASON,\n" +
                "   STYLE_PUBLISH_CATEGORY_CD \n" +
                "FROM\n" +
                "	s_style_p \n" +
                "WHERE\n" +
                "	SYS_STYLE_ID = '" + REF_STYLE_ID + "'";

            return SQLmtm.GetDataRow(sql);
        }

        /// <summary>
        /// 查找款式
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DataTable initStyle(String str, int page)
        {
            DataTable dt = SQLmtm.GetDataTable("SELECT\n" +
                " style.SYS_STYLE_ID AS styleId,\n" +
                " style.STYLE_CD \"styleEntity.styleCd\",\n" +
                " style.STYLE_NAME_CN \"styleEntity.styleNameCn\",\n" +
                " style.STYLE_CATEGORY_CD \"styleEntity.styleCategoryCd\",\n" +
                " style.STYLE_DRESS_CATEGORY \"styleEntity.styleDressCategory\",\n" +
                " style.STYLE_DESIGN_TYPE \"styleEntity.styleDesignType\",\n" +
                " style.STYLE_PUBLISH_CATEGORY_CD \"styleEntity.stylePublishCategoryCd\",\n" +
                " style.SYTLE_YEAR \"styleEntity.sytleYear\",\n" +
                " style.SYTLE_SEASON \"styleEntity.sytleSeason\",\n" +
                " style.STYLE_FIT_CD \"styleEntity.styleFitCd\",\n" +
                " material.MATERIAL_NAME_CN AS \"materialEntity.materialNameCn\",\n" +
                " material.MATERIAL_NAME_EN AS \"materialEntity.materialNameEn\",\n" +
                " material.material_id \"materialEntity.id\",\n" +
                " GROUP_CONCAT( DISTINCT material.MATERIAL_CODE ) \"materialEntity.materialCode\",\n" +
                " style.VERSION,\n" +
                " style.CREATE_USER,\n" +
                " style.STYLE_MAKE_TYPE \"styleEntity.styleMakeType\",\n" +
                " style.STYLE_SIZE_GROUP_CD \"styleEntity.styleSizeGroupCd\",\n" +
                " style.STYLE_SIZE_CD \"styleEntity.styleSizeCd\",\n" +
                " style.STYLE_FIT_BODY_TYPE \"styleEntity.styleFitBodyType\",\n" +
                " CONCAT( login_user.FIRST_NAME, login_user.LAST_NAME ) \"user.loginName\",\n" +
                " style.CREATE_DATE,\n" +
                " style.COVER_PHOTO_PATH \"styleEntity.coverPhotoPath\", \n" +
                "SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1) AS picn," +
                " CONCAT('https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/',SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1)) AS picurl \n" +
                "FROM\n" +
                " s_style_p style\n" +
                " LEFT JOIN i_material_p material ON FIND_IN_SET( CAST( material.MATERIAL_ID AS CHAR ), style.SYTLE_FABRIC_ID )\n" +
                " LEFT JOIN a_login_user_p login_user ON login_user.LOGIN_USER_ID = style.CREATE_USER \n" +
                "WHERE\n" +
                " style.DELETE_FLAG = 0 \n" +
                " AND style.STYLE_NAME_CN IS NOT NULL \n" +
                "   AND style.STYLE_KBN != 'STYLE_SOURCE-STYLE_SOURCE_50' \n" +
                " AND ( style.SHOP_ID = 18 OR style.SHOP_ID = 0 )\n" +
                "AND style.STYLE_NAME_CN LIKE '%" + str + "%'\n" +
                "GROUP BY\n" +
                " style.SYS_STYLE_ID \n" +
                "ORDER BY\n" +
                " style.UPDATE_DATE DESC \n" +
                " LIMIT " + ((page - 1) * 21).ToString() + ",21");
            return dt;
        }

        /// <summary>
        /// 获得款式所有尺码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DataTable StyleCombobox(String styleid)
        {
            DataRow dr = SQLmtm.GetDataRow("SELECT SYS_STYLE_ID,SHOP_ID,STYLE_NO,CUSTOMER_COUNT_ID,STYLE_CD,STYLE_KBN,STYLE_SOURCE,STYLE_CATEGORY_CD,STYLE_DRESS_CATEGORY,STYLE_DESIGN_TYPE,STYLE_PUBLISH_CATEGORY_CD,REF_STYLE_ID,STYLE_NAME_CN,STYLE_NAME_EN,STYLE_FIT_CD,SYTLE_YEAR,SYTLE_SEASON,SYTLE_FABRIC_ID,SYTLE_FABRIC_NO,STYLE_COMPOSITION,STYLE_DESCRIBE,STYLE_COLOR_CD,STYLE_COLOR_NAME,STYLE_SIZE_GROUP_CD,STYLE_SIZE_CD,STYLE_MAKE_TYPE,STYLE_FIT_BODY_TYPE,STYLE_SEX_CD,STYLE_STANDARD,STYLE_BAR_CODE,STYLE_DESIGNER_DATE,STYLE_DESIGNER,STYLE_MATERIAL_NUMBER,STYLE_DESIGN_PRICE,STYLE_FACTORY_TOTAL_PRICE,STYLE_SHOP_TOTAL_PRICE,REMARKS,ENABLE_FLAG,DELETE_FLAG,VERSION,CREATE_DATE,UPDATE_DATE,CREATE_USER,UPDATE_USER,COVER_PHOTO_PATH FROM s_style_p WHERE SYS_STYLE_ID = '" + styleid + "'");
            DataTable dt = new DataTable();
            try
            {
                String sql = " SELECT\n" +
                    "-- 	*,\n" +
                    " DISTINCT SIZE_CD,\n" +
                    " SUBSTRING_INDEX( SIZE_CD, '-',- 1 ) AS 尺寸\n" +
                    "FROM\n" +
                    "	`a_size_fit_p` \n" +
                    "WHERE\n" +
                    "	FIT_CD = '" + dr["STYLE_FIT_CD"].ToString() + "' \n" +
                    "	AND STYLE_CATEGORY_CD = '" + dr["STYLE_CATEGORY_CD"].ToString() + "' \n" +
                    "	AND DEL_FLG <> '1' \n" +
                    "	AND SIZEGROUP_CD = '" + dr["STYLE_SIZE_GROUP_CD"] + "';";
                dt = SQLmtm.GetDataTable(sql);
            }
            catch
            {

            }
            return dt;
        }

        /// <summary>
        /// 获得款式所有尺码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DataTable StyleCombobox(DataRow dr, String str)
        {
            DataTable dt = new DataTable();
            try
            {
                String sql = " SELECT\n" +
                    "-- 	*,\n" +
                    " DISTINCT SIZE_CD,\n" +
                    " SUBSTRING_INDEX( SIZE_CD, '-',- 1 ) AS 尺寸\n" +
                    "FROM\n" +
                    "	`a_size_fit_p` \n" +
                    "WHERE\n" +
                    "	FIT_CD = '" + dr["STYLE_FIT_CD"].ToString() + "' \n" +
                    "	AND STYLE_CATEGORY_CD = '" + dr["STYLE_CATEGORY_CD"].ToString() + "' \n" +
                    "	AND SIZEGROUP_CD = '" + dr["STYLE_SIZE_GROUP_CD"] + "';";
                dt = SQLmtm.GetDataTable(sql);
            }
            catch
            {

            }
            return dt;
        }

        public static List<款式图片Dto> initStyleInfo(String flag, int page)
        {
            DataTable dt = SQLmtm.GetDataTable("SELECT\n" +
                " style.SYS_STYLE_ID AS styleId,\n" +
                " style.STYLE_CD \"styleEntity.styleCd\",\n" +
                " style.STYLE_NAME_CN \"styleEntity.styleNameCn\",\n" +
                " style.STYLE_CATEGORY_CD \"styleEntity.styleCategoryCd\",\n" +
                " style.STYLE_DRESS_CATEGORY \"styleEntity.styleDressCategory\",\n" +
                " style.STYLE_DESIGN_TYPE \"styleEntity.styleDesignType\",\n" +
                " style.STYLE_PUBLISH_CATEGORY_CD \"styleEntity.stylePublishCategoryCd\",\n" +
                " style.SYTLE_YEAR \"styleEntity.sytleYear\",\n" +
                " style.SYTLE_SEASON \"styleEntity.sytleSeason\",\n" +
                " style.STYLE_FIT_CD \"styleEntity.styleFitCd\",\n" +
                " material.MATERIAL_NAME_CN AS \"materialEntity.materialNameCn\",\n" +
                " material.MATERIAL_NAME_EN AS \"materialEntity.materialNameEn\",\n" +
                " material.material_id \"materialEntity.id\",\n" +
                " GROUP_CONCAT( DISTINCT material.MATERIAL_CODE ) \"materialEntity.materialCode\",\n" +
                " style.VERSION,\n" +
                " style.CREATE_USER,\n" +
                " style.STYLE_MAKE_TYPE \"styleEntity.styleMakeType\",\n" +
                " style.STYLE_SIZE_GROUP_CD \"styleEntity.styleSizeGroupCd\",\n" +
                " style.STYLE_SIZE_CD \"styleEntity.styleSizeCd\",\n" +
                " style.STYLE_FIT_BODY_TYPE \"styleEntity.styleFitBodyType\",\n" +
                " CONCAT( login_user.FIRST_NAME, login_user.LAST_NAME ) \"user.loginName\",\n" +
                " style.CREATE_DATE,\n" +
                " style.STYLE_SHOP_TOTAL_PRICE,\n"+
                " style.COVER_PHOTO_PATH \"styleEntity.coverPhotoPath\", \n" +
                "SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1) AS picn," +
                " CONCAT('https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/',SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1)) AS picurl \n" +
                "FROM\n" +
                " s_style_p style\n" +
                " LEFT JOIN i_material_p material ON FIND_IN_SET( CAST( material.MATERIAL_ID AS CHAR ), style.SYTLE_FABRIC_ID )\n" +
                " LEFT JOIN a_login_user_p login_user ON login_user.LOGIN_USER_ID = style.CREATE_USER \n" +
                "WHERE\n" +
                " style.DELETE_FLAG = 0 \n" +
                " and style.ENABLE_FLAG = 1 \n" +
                " AND style.STYLE_NAME_CN IS NOT NULL \n" +
                "   AND style.STYLE_KBN != 'STYLE_SOURCE-STYLE_SOURCE_50' \n" +
                " AND ( style.SHOP_ID = 18 OR style.SHOP_ID = 0 )\n" +
                "AND style.STYLE_NAME_CN LIKE '%" + flag + "%'\n" +
                "GROUP BY\n" +
                " style.SYS_STYLE_ID \n" +
                "ORDER BY\n" +
                " style.UPDATE_DATE DESC \n" 
                //+" LIMIT " + ((page - 1) * 42).ToString() + ",42"
                );
            List<款式图片Dto> 款式图片Dtos = new List<款式图片Dto>();
            foreach (DataRow dataRow in dt.Rows)
            {
                款式图片Dtos.Add(new 款式图片Dto(flag, dataRow));
            }

            return 款式图片Dtos;
        }

        /// <summary>
        /// 取款式信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static DataRow GetDataRowFromOrder(String id)
        {
            String sql = "SELECT\n" +
                "	sp.SYS_STYLE_ID,\n" +
                "	sp.STYLE_NAME_CN,\n" +
                "	imp.MATERIAL_CODE,\n" +
                "	imp.MATERIAL_COMPOSITION,\n" +
                "	sp.STYLE_SHOP_TOTAL_PRICE,\n" +
                "	sp.STYLE_FIT_CD,\n" +
                "	sp.STYLE_CATEGORY_CD,\n" +
                "	sp.STYLE_SIZE_GROUP_CD,sp.STYLE_SIZE_CD,SUBSTRING_INDEX( sp.STYLE_SIZE_CD, '-',- 1 ) AS SIZE\n" +
                "FROM\n" +
                "	s_style_p AS sp\n" +
                "	LEFT JOIN i_material_p imp ON sp.SYTLE_FABRIC_ID = imp.MATERIAL_ID \n" +
                "WHERE\n" +
                "	sp.SYS_STYLE_ID IN ( SELECT op.STYLE_ID FROM o_order_p AS op WHERE ORDER_NO like '%" + id + "%' );";
            return SQLmtm.GetDataRow(sql);
        }

        /// <summary>
        /// 获得最新的styleid
        /// </summary>
        /// <returns></returns>
        public static int GetNewStyleID()
        {
            DataRow drstyle = SQLmtm.GetDataRow("SELECT MAX(SYS_STYLE_ID) SYS_STYLE_ID FROM `s_style_p`");
            return (Convert.ToInt32(drstyle["SYS_STYLE_ID"]) + 1);
        }
        /// <summary>
        /// 通过styleid获得refstyleid,style_fit_cd
        /// </summary>
        /// <param name="styleid"></param>
        /// <returns></returns>
        public static DataRow GetRefsidSFCBySid(String styleid)
        {
            String sql = "SELECT\n" +
                "	REF_STYLE_ID,\n" +
                "	STYLE_FIT_CD \n" +
                "FROM\n" +
                "	s_style_p \n" +
                "WHERE\n" +
                "	SYS_STYLE_ID = '"+styleid+"'";
            return SQLmtm.GetDataRow(sql);
        }
        /// <summary>
        /// 检索版型下的款式
        /// </summary>
        /// <param name="Fit_CD"></param>
        /// <returns></returns>
        public static DataTable GetStyleByFitCd(String Fit_CD)
        {
            #region sql
            String sql = "SELECT\n" +
                    "	style.SYS_STYLE_ID AS styleId,\n" +
                    "	style.STYLE_CD,\n" +
                    "	style.STYLE_NAME_CN,\n" +
                    "	style.STYLE_CATEGORY_CD,\n" +
                    "	style.STYLE_DRESS_CATEGORY,\n" +
                    "	style.STYLE_DESIGN_TYPE,\n" +
                    "	style.STYLE_PUBLISH_CATEGORY_CD,\n" +
                    "	style.SYTLE_YEAR,\n" +
                    "	style.SYTLE_SEASON,\n" +
                    "	style.STYLE_FIT_CD,\n" +
                    "	material.MATERIAL_NAME_CN,\n" +
                    "	material.MATERIAL_NAME_EN,\n" +
                    "	material.material_id,\n" +
                    "	GROUP_CONCAT( DISTINCT material.MATERIAL_CODE ),\n" +
                    "	style.VERSION,\n" +
                    "	style.CREATE_USER,\n" +
                    "	style.STYLE_MAKE_TYPE,\n" +
                    "	style.STYLE_SIZE_GROUP_CD,\n" +
                    "	style.STYLE_SIZE_CD,\n" +
                    "	style.STYLE_FIT_BODY_TYPE,\n" +
                    "	CONCAT( login_user.FIRST_NAME, login_user.LAST_NAME ),\n" +
                    "	style.CREATE_DATE,\n" +
                    "	style.COVER_PHOTO_PATH,\n" +
                    "	SUBSTRING_INDEX( style.COVER_PHOTO_PATH, '/',- 1 ) AS picn,\n" +
                    "	CONCAT( 'https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/', SUBSTRING_INDEX( style.COVER_PHOTO_PATH, '/',- 1 ) ) AS picurl \n" +
                    "FROM\n" +
                    "	s_style_p style\n" +
                    "	LEFT JOIN i_material_p material ON FIND_IN_SET( CAST( material.MATERIAL_ID AS CHAR ), style.SYTLE_FABRIC_ID )\n" +
                    "	LEFT JOIN a_login_user_p login_user ON login_user.LOGIN_USER_ID = style.CREATE_USER \n" +
                    "WHERE\n" +
                    "	style.DELETE_FLAG = 0 \n" +
                    "	AND style.STYLE_NAME_CN IS NOT NULL \n" +
                    "	AND style.STYLE_KBN != 'STYLE_SOURCE-STYLE_SOURCE_50' \n" +
                    "	AND ( style.SHOP_ID = 18 OR style.SHOP_ID = 0 ) -- AND style.STYLE_NAME_CN LIKE '%+ str + \"%'\n" +
                    "	\n" +
                    "	AND style.STYLE_FIT_CD = '"+Fit_CD+"' \n" +
                    "GROUP BY\n" +
                    "	style.SYS_STYLE_ID \n" +
                    "ORDER BY\n" +
                    "	style.UPDATE_DATE DESC -- LIMIT + ((page - 1) * 21).ToString() + \",21\");";
            #endregion
            return SQLmtm.GetDataTable(sql);
        }
        /// <summary>
        /// 查询所有STYLE_DRESS_CATEGORY
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSTYLE_DRESS_CATEGORY()
        {
            String sql = "SELECT * FROM `w_dict_option_p` WHERE ITEM_CD='STYLE_DRESS_CATEGORY'";
            return SQLmtm.GetDataTable(sql);
        }
        /// <summary>
        /// 查询所有PUBLISH_STYLE_CATEGORY
        /// </summary>
        /// <returns></returns>
        public static DataTable GetPUBLISH_STYLE_CATEGORY()
        {
            String sql = "SELECT * FROM `w_dict_option_p` WHERE ITEM_CD='PUBLISH_STYLE_CATEGORY'";
            return SQLmtm.GetDataTable(sql);
        }
        /// <summary>
        /// 查询所有STYLE_DESIGN_TYPE
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSTYLE_DESIGN_TYPE()
        {
            String sql = "SELECT * FROM `w_dict_option_p` WHERE ITEM_CD='STYLE_DESIGN_TYPE'";
            return SQLmtm.GetDataTable(sql);
        }
        /// <summary>
        /// 创建版型款式
        /// </summary>
        /// <param name="STYLE_DRESS_CATEGORY"></param>
        /// <param name="STYLE_DESIGN_TYPE"></param>
        /// <param name="STYLE_PUBLISH_CATEGORY_CD"></param>
        /// <param name="STYLE_NAME_CN"></param>
        /// <param name="STYLE_FIT_CD"></param>
        /// <param name="SYTLE_YEAR"></param>
        /// <param name="SYTLE_SEASON"></param>
        /// <param name="SYTLE_FABRIC_ID"></param>
        public static void CreateStyleByFit(String STYLE_DRESS_CATEGORY,String STYLE_DESIGN_TYPE, String STYLE_PUBLISH_CATEGORY_CD,String STYLE_NAME_CN,String STYLE_FIT_CD,String SYTLE_YEAR,String SYTLE_SEASON,String SYTLE_FABRIC_ID)
        {
            SQLmtm.DoInsert("s_style_p", new string[] { "SHOP_ID", "STYLE_CD", "STYLE_KBN", "STYLE_CATEGORY_CD", "STYLE_DRESS_CATEGORY", "STYLE_DESIGN_TYPE", "STYLE_PUBLISH_CATEGORY_CD", "STYLE_NAME_CN", "STYLE_FIT_CD", "SYTLE_YEAR", "SYTLE_SEASON", "SYTLE_FABRIC_ID", "STYLE_SIZE_GROUP_CD", "STYLE_SIZE_CD", "STYLE_MAKE_TYPE", "STYLE_MATERIAL_NUMBER", "STYLE_DESIGN_PRICE", "STYLE_SHOP_TOTAL_PRICE", "ENABLE_FLAG", "DELETE_FLAG", "VERSION", "CREATE_USER", "UPDATE_USER", "STYLE_NAME_EN" }, new string[] { "18", 门店下单选款式Model.getSTYLE_CD(), "STYLE_SOURCE-STYLE_SOURCE_40", "STYLE_CATEGORY-SHIRT", STYLE_DRESS_CATEGORY, STYLE_DESIGN_TYPE, STYLE_PUBLISH_CATEGORY_CD, STYLE_NAME_CN, STYLE_FIT_CD, SYTLE_YEAR, SYTLE_SEASON, SYTLE_FABRIC_ID, "GROUP_SIZE-IGS_GROUP_SIZE", "IGS_GROUP_SIZE-XXS", "4SMA-4M", "", "", "", "0", "0", "1", "46", "46" , "Sample" });
        }
        /// <summary>
        /// 样品款式图片
        /// </summary>
        /// <param name="flag"></param>
        /// <returns></returns>
        public static List<款式图片Dto> initSampleStyleInfo(String flag)
        {
            DataTable dt = SQLmtm.GetDataTable("SELECT\n" +
                " style.SYS_STYLE_ID AS styleId,\n" +
                " style.STYLE_CD \"styleEntity.styleCd\",\n" +
                " style.STYLE_NAME_CN \"styleEntity.styleNameCn\",\n" +
                " style.STYLE_CATEGORY_CD \"styleEntity.styleCategoryCd\",\n" +
                " style.STYLE_DRESS_CATEGORY \"styleEntity.styleDressCategory\",\n" +
                " style.STYLE_DESIGN_TYPE \"styleEntity.styleDesignType\",\n" +
                " style.STYLE_PUBLISH_CATEGORY_CD \"styleEntity.stylePublishCategoryCd\",\n" +
                " style.SYTLE_YEAR \"styleEntity.sytleYear\",\n" +
                " style.SYTLE_SEASON \"styleEntity.sytleSeason\",\n" +
                " style.STYLE_FIT_CD \"styleEntity.styleFitCd\",\n" +
                " material.MATERIAL_NAME_CN AS \"materialEntity.materialNameCn\",\n" +
                " material.MATERIAL_NAME_EN AS \"materialEntity.materialNameEn\",\n" +
                " material.material_id \"materialEntity.id\",\n" +
                " GROUP_CONCAT( DISTINCT material.MATERIAL_CODE ) \"materialEntity.materialCode\",\n" +
                " style.VERSION,\n" +
                " style.CREATE_USER,\n" +
                " style.STYLE_MAKE_TYPE \"styleEntity.styleMakeType\",\n" +
                " style.STYLE_SIZE_GROUP_CD \"styleEntity.styleSizeGroupCd\",\n" +
                " style.STYLE_SIZE_CD \"styleEntity.styleSizeCd\",\n" +
                " style.STYLE_FIT_BODY_TYPE \"styleEntity.styleFitBodyType\",\n" +
                " CONCAT( login_user.FIRST_NAME, login_user.LAST_NAME ) \"user.loginName\",\n" +
                " style.CREATE_DATE,\n" +
                " style.STYLE_SHOP_TOTAL_PRICE,\n" +
                " style.COVER_PHOTO_PATH \"styleEntity.coverPhotoPath\", \n" +
                "SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1) AS picn," +
                " CONCAT('https://sshirtmtmbucket.oss-cn-zhangjiakou.aliyuncs.com/sshirtmtm/',SUBSTRING_INDEX(style.COVER_PHOTO_PATH,'/',-1)) AS picurl \n" +
                "FROM\n" +
                " s_style_p style\n" +
                " LEFT JOIN i_material_p material ON FIND_IN_SET( CAST( material.MATERIAL_ID AS CHAR ), style.SYTLE_FABRIC_ID )\n" +
                " LEFT JOIN a_login_user_p login_user ON login_user.LOGIN_USER_ID = style.CREATE_USER \n" +
                "WHERE\n" +
                " style.DELETE_FLAG = 0 \n" +
                " and style.ENABLE_FLAG = 1 \n" +
                " AND style.STYLE_NAME_EN = 'Sample' \n" +
                " AND style.STYLE_NAME_CN IS NOT NULL \n" +
                "   AND style.STYLE_KBN != 'STYLE_SOURCE-STYLE_SOURCE_50' \n" +
                " AND ( style.SHOP_ID = 18 OR style.SHOP_ID = 0 )\n" +
                "AND style.STYLE_NAME_CN LIKE '%" + flag + "%'\n" +
                "GROUP BY\n" +
                " style.SYS_STYLE_ID \n" +
                "ORDER BY\n" +
                " style.UPDATE_DATE DESC \n"
                //+" LIMIT " + ((page - 1) * 42).ToString() + ",42"
                );
            List<款式图片Dto> 款式图片Dtos = new List<款式图片Dto>();
            foreach (DataRow dataRow in dt.Rows)
            {
                款式图片Dtos.Add(new 款式图片Dto(flag, dataRow));
            }

            return 款式图片Dtos;
        }
        /// <summary>
        /// 取得所有尺码
        /// </summary>
        /// <returns></returns>
        public static DataTable getAllSizeCD()
        {
            String sql = "SELECT DISTINCT\n" +
                    "	SUBSTRING_INDEX( SIZE_CD, '-',- 1 ) AS ITEM,\n" +
                    "	SIZE_CD AS `VALUE` \n" +
                    "FROM\n" +
                    "	a_size_fit_p \n" +
                    "WHERE\n" +
                    "	SIZEGROUP_CD = 'GROUP_SIZE-IGS_GROUP_SIZE';";
            return SQLmtm.GetDataTable(sql);
        }
        /// <summary>
        /// 取得所有版型
        /// </summary>
        /// <returns></returns>
        public static DataTable getAllFitCD()
        {
            String sql = "SELECT DISTINCT\n" +
                    "	SUBSTRING_INDEX( FIT_CD, '-',- 1 ) AS ITEM,\n" +
                    "	FIT_CD AS `VALUE` \n" +
                    "FROM\n" +
                    "	a_size_fit_p;";
            return SQLmtm.GetDataTable(sql);
        }

        public static DataTable getSTYLE_CATEGORY_CD()
        {
            String sql = "SELECT\n" +
                "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                "FROM\n" +
                "	a_dict_p \n" +
                "WHERE\n" +
                "	ITEM_VALUE = 'SHIRT' \n" +
                "	AND ITEM_CD = 'STYLE_CATEGORY'";
            return SQLmtm.GetDataTable(sql);
        }
        public static DataTable getSTYLE_DRESS_CATEGORY()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                    "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                    "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                    "FROM\n" +
                    "	w_dict_option_p \n" +
                    "WHERE\n" +
                    "	ITEM_CD = 'STYLE_DRESS_CATEGORY'");
        }
        public static DataTable getSTYLE_DESIGN_TYPE()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                    "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                    "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                    "FROM\n" +
                    "	w_dict_option_p \n" +
                    "WHERE\n" +
                    "	ITEM_CD = 'STYLE_DESIGN_TYPE'");
        }
        public static DataTable getSTYLE_PUBLISH_CATEGORY_CD()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                "FROM\n" +
                "	w_dict_option_p \n" +
                "WHERE\n" +
                "	ITEM_CD = 'PUBLISH_STYLE_CATEGORY'");
        }
        public static DataTable getSYTLE_SEASON()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                "FROM\n" +
                "	a_dict_p \n" +
                "WHERE\n" +
                "	ITEM_CD = 'SEASON' \n" +
                "	AND ITEM_VALUE IS NOT NULL \n" +
                "	AND ITEM_VALUE <> ''");
        }
        public static DataTable getSTYLE_MAKE_TYPE()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                            "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                            "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                            "FROM\n" +
                            "	a_designoption_p \n" +
                            "WHERE\n" +
                            "	ITEM_CD = '4SMA' \n" +
                            "	AND ITEM_VALUE IS NOT NULL \n" +
                            "	AND ITEM_VALUE <> '';");
        }
        public static DataTable getSTYLE_SIZE_GROUP_CD()
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                "	CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                "FROM\n" +
                "	a_dict_p \n" +
                "WHERE\n" +
                "	ITEM_CD = 'GROUP_SIZE' \n" +
                "	AND ITEM_VALUE IS NOT NULL \n" +
                "	AND ITEM_VALUE <> ''");
        }
        public static DataTable getSTYLE_SIZE_CD(String item_cd)
        {
            return SQLmtm.GetDataTable("SELECT\n" +
                "	CONCAT( ITEM_CD, '-', ITEM_VALUE ) AS `Value`,\n" +
                "	-- CONCAT( ITEM_VALUE, ':', ITEM_NAME_CN ) AS `Display` \n" +
                "	ITEM_NAME_CN AS `Display`\n" +
                "FROM\n" +
                "	a_dict_p \n" +
                "WHERE\n" +
                "	ITEM_CD = '"+item_cd+"' \n" +
                "	AND ITEM_VALUE IS NOT NULL \n" +
                "	AND ITEM_VALUE <> ''");
        }
        /// <summary>
        /// 新增款式基本信息
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        public static Boolean CreateStyle(款式图片一览Dto Dto)
        {
            #region Sql
            String sql = "INSERT INTO `fragsmart-mtm`.`s_style_p` (\n" +
                    "	`SHOP_ID`,\n" +
                    "	`STYLE_CD`,\n" +
                    "	`STYLE_KBN`,\n" +
                    "	`STYLE_CATEGORY_CD`,\n" +
                    "	`STYLE_DRESS_CATEGORY`,\n" +
                    "	`STYLE_DESIGN_TYPE`,\n" +
                    "	`STYLE_PUBLISH_CATEGORY_CD`,\n" +
                    "	`STYLE_NAME_CN`,\n" +
                    "	`STYLE_FIT_CD`,\n" +
                    "	`SYTLE_YEAR`,\n" +
                    "	`SYTLE_SEASON`,\n" +
                    "	`STYLE_SIZE_GROUP_CD`,\n" +
                    "	`STYLE_SIZE_CD`,\n" +
                    "	`STYLE_MAKE_TYPE`,\n" +
                    "	`STYLE_MATERIAL_NUMBER`,\n" +
                    "	`STYLE_DESIGN_PRICE`,\n" +
                    "	`STYLE_SHOP_TOTAL_PRICE`,\n" +
                    "	`ENABLE_FLAG`,\n" +
                    "	`DELETE_FLAG`,\n" +
                    "	`VERSION`,\n" +
                    "	`CREATE_USER`,\n" +
                    "	`UPDATE_USER`,\n" +
                    "	`COVER_PHOTO_PATH` \n" +
                    ")\n" +
                    "VALUES\n" +
                    "	(\n" +
                    "		18,\n" +
                    "		'" + 门店下单选款式Model.getSTYLE_CD() + "',\n" +
                    "		'STYLE_SOURCE-STYLE_SOURCE_40',\n" +
                    "		'" + Dto.STYLE_CATEGORY_CD + "',\n" +
                    "		'" + Dto.STYLE_DRESS_CATEGORY + "',\n" +
                    "		'" + Dto.STYLE_DESIGN_TYPE + "',\n" +
                    "		'" + Dto.STYLE_PUBLISH_CATEGORY_CD + "',\n" +
                    "		'" + Dto.STYLE_NAME_CN + "',\n" +
                    "		'" + Dto.STYLE_FIT_CD + "',\n" +
                    "		'" + Dto.SYTLE_YEAR + "',\n" +
                    "		'" + Dto.SYTLE_SEASON + "',\n" +
                    "		'" + Dto.STYLE_SIZE_GROUP_CD + "',\n" +
                    "		'" + Dto.STYLE_SIZE_CD + "',\n" +
                    "		'"+Dto.STYLE_MAKE_TYPE + "',\n" +
                    "		"+ Dto.STYLE_MATERIAL_NUMBER + ",\n" +
                    "		"+Dto.STYLE_DESIGN_PRICE + ",\n" +
                    "		NULL,\n" +
                    "		1,\n" +
                    "		0,\n" +
                    "		1,\n" +
                    "		46,\n" +
                    "		NULL,\n" +
                    "    NULL \n" +
                    "	);";
            #endregion
            try
            {
                SQLmtm.ExecuteSql(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 更新款式基本信息
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        public static Boolean UpdataStyle(款式图片一览Dto Dto)
        {
            #region sql
            String sql = "UPDATE `fragsmart-mtm`.`s_style_p` \n" +
                    "SET `SHOP_ID` = 18,\n" +
                    "`STYLE_CATEGORY_CD` = '" + Dto.STYLE_CATEGORY_CD + "',\n" +
                    "`STYLE_DRESS_CATEGORY` = '" + Dto.STYLE_DRESS_CATEGORY + "',\n" +
                    "`STYLE_DESIGN_TYPE` = '" + Dto.STYLE_DESIGN_TYPE + "',\n" +
                    "`STYLE_PUBLISH_CATEGORY_CD` = '" + Dto.STYLE_PUBLISH_CATEGORY_CD + "',\n" +
                    "`STYLE_NAME_CN` = '" + Dto.STYLE_NAME_CN + "',\n" +
                    "`SYTLE_YEAR` = '" + Dto.SYTLE_YEAR + "',\n" +
                    "`SYTLE_SEASON` = '" + Dto.SYTLE_SEASON + "',\n" +
                    "`STYLE_SIZE_GROUP_CD` = '" + Dto.STYLE_SIZE_GROUP_CD + "',\n" +
                    "`STYLE_SIZE_CD` = '" + Dto.STYLE_SIZE_CD + "',\n" +
                    "`STYLE_MAKE_TYPE` = '" + Dto.STYLE_MAKE_TYPE + "',\n" +
                    "`STYLE_MATERIAL_NUMBER` = " + Dto.STYLE_MATERIAL_NUMBER + ",\n" +
                    "`STYLE_DESIGN_PRICE` = " + Dto.STYLE_DESIGN_PRICE + ",\n" +
                    "`STYLE_FIT_CD` = '" + Dto.STYLE_FIT_CD + "'\n" +
                    "WHERE\n" +
                    "	`SYS_STYLE_ID` = '" + Dto.SYS_STYLE_ID + "';";
            #endregion
            try
            {
                SQLmtm.ExecuteSql(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 取春衫店铺款式
        /// </summary>
        /// <returns></returns>
        public static DataTable Get18Styles()
        {
            String sql = "SELECT\n" +
                    "	SYS_STYLE_ID AS ID,\n" +
                    "	STYLE_NAME_CN AS `Name` \n" +
                    "FROM\n" +
                    "	s_style_p \n" +
                    "WHERE\n" +
                    "	s_style_p.DELETE_FLAG = 0 \n" +
                    "	AND s_style_p.ENABLE_FLAG = 1 \n" +
                    "	AND s_style_p.STYLE_NAME_CN IS NOT NULL \n" +
                    "	AND s_style_p.STYLE_KBN != 'STYLE_SOURCE-STYLE_SOURCE_50';";
            return SQLmtm.GetDataTable(sql);
        }

        public static void BuildStyleWithRefStyle(String StyleCD,String StyleNA,String RefStyleid)
        {

        }
        /// <summary>
        /// 取得所有款式类别
        /// </summary>
        /// <returns></returns>
        public static DataTable GetAllSTYLE_CATEGORY()
        {
            String sql = "SELECT\n" +
                "	ITEM_VALUE AS `ID`,\n" +
                "	ITEM_NAME_CN AS `Name`,\n" +
                "	CONCAT( 'STYLE_CATEGORY-', ITEM_VALUE ) AS `CD` \n" +
                "FROM\n" +
                "	a_dict_p \n" +
                "WHERE\n" +
                "	ITEM_CD = 'STYLE_CATEGORY' \n" +
                "	AND ITEM_VALUE <> \"\";";
            return SQLmtm.GetDataTable(sql);
        }
    }
}
